/*************************************************************************
	> File Name: oj-199_fxkmod.c
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年10月23日 星期五 13时27分31秒
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>

void swap(int *a, int *b) {
    int *temp = a;
    a = b;
    b = temp;
}

int newfkmod(int a[], int temp[], int k, int m) {
    if (k < 10) return k % m;
    while (k-- > 10) {
        int x = 0;
        for (int i = 1; i <= 10; ++i) {
            //printf("a[%d]: %d, temp[%d]: %d\n", i, a[i], i, temp[i]);
            if (a[i]) x += temp[i];
        }
        for (int i = 10; i >= 1; --i) {
            //printf("swap temp[%d] and temp[%d]\n", i - 1, i);
            int t = temp[i - 1];
            temp[i - 1] = temp[i];
            temp[i] = t;
            //printf("after swap temp[%d]: %d\n", i, temp[i]);
        }
        //printf("before temp[1]: %d\n", temp[1]);
        temp[1] = x % m;
        //printf("after temp[1]: %d\n", temp[1]);
    }
    int ret = 0;
    for (int i = 1; i <= 10; ++i) {
        if (a[i]) ret += temp[i];
    }
    return ret % m;
}

int main() {
    int k, m, a[11], temp[11] = {
        0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
    };
    int *p = temp;
    scanf("%d%d", &k, &m);
    for (int i = 1; i <= 10; ++i) {
        scanf("%d", &a[i]);
    }
    printf("%d", newfkmod(a, temp, k, m));
    return 0;
}
